/*
 * spi_io.h
 *
 *  Created on: Sep 30, 2013
 *      Author: Ken Arok
 */


#include "io.h"


/** \brief SPI Initialization.
 *
 * \param _master_slave 	CONFIG_SPI_MASTER = Init as Master;
 * 							CONFIG_SPI_SLAVE = Init as Slave;
 */
extern void spi_io_init(uint8_t _master_slave);


/** \brief UART I/O Control.
 *
 * \param spiPort		SPI port.
 * \param reqCode		Request Code.
 * \param pValue		Pointer to the value.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
extern uint8_t spi_io_ctrl(io_port_t spiPort, io_request_code_t reqCode, void *pValue);


/** \brief SPI Open Peripheral.
 *
 * \param spiPort		SPI port.
 * \param flag			Flag of opening.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
extern uint8_t spi_io_open(io_port_t spiPort, const uint8_t flag);

/** \brief SPI Close Peripheral.
 *
 * \param spiPort		SPI port.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
extern uint8_t spi_io_close(io_port_t spiPort);

/** \brief SPI Write Data to Peripheral.
 *
 * \param spiPort		SPI port.
 * \param pBuff			Pointer to the buffer of data to write.
 * \param size			Size of data to write.
 * \param flag			Flag of writing operation.
 *
 * \return	status		pdPASS = Success, pdFAIL = failed.
 *
 */
extern uint8_t spi_io_write(io_port_t spiPort, const void *pBuf, uint32_t size, io_rw_flag_t flag);

/** \brief SPI Read Data from Peripheral.
 *
 * \param spiPort		SPI port.
 * \param pBuff			Pointer to the buffer where data will be copied.
 * \param size			Size of data to read.
 * \param flag			Flag of writing operation.
 *
 * \return actual number of count of received data.
 *
 */
extern uint32_t spi_io_read(io_port_t spiPort, void *pBuf, uint32_t size, io_rw_flag_t flag);
